﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Collections;


using ComLib;
using ComLib.Extensions;
using ComLib.Entities;
using ComLib.Authentication;



namespace ComLib.Mvc.Lib
{
    /// <summary>
    /// Base class for controllers.
    /// </summary>
    public class EntityControllerAutomaticDataBinding<T> : EntityControllerBase<T> where T : class, IEntity, new()
    {
        /// <summary>
        /// Create a new entity.
        /// </summary>
        /// <returns></returns>
        [Authorize]
        public override ActionResult Create()
        {
            return base.Create();
        }


        /// <summary>
        /// Create the entity and persist it.
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        [AcceptVerbs(HttpVerbs.Post), Authorize]
        public virtual ActionResult Create(T entity)
        {
            return Create(entity, Conf.GetOrDefault<string>("CreateSuccessUrl", "Details"));
        }
    }



    /// <summary>
    /// Base class for controllers.
    /// </summary>
    public class EntityControllerManualDataBinding<T> : EntityControllerBase<T> where T : class, IEntity, new()
    {
        /// <summary>
        /// Create a new entity.
        /// </summary>
        /// <returns></returns>
        [Authorize]
        public override ActionResult Create()
        {
            return base.Create();
        }


        /// <summary>
        /// Create the entity and persist it.
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        [AcceptVerbs(HttpVerbs.Post), Authorize]
        public virtual ActionResult Create(FormCollection form)
        {
            T entity = new T();
            UpdateModel(entity);
            return Create(entity, Conf.GetOrDefault<string>("CreateSuccessUrl", "Details"));
        }
    }
}
